package chapter15;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/3/14 14:06
 */
class ClassAsFactory<T>{
    T x;
    public ClassAsFactory(Class<T> type){
        try {
            x = type.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}

class Employee{}

public class InstantiateGenericType {
    public static void main(String[] args) {
        ClassAsFactory<Employee> fe = new ClassAsFactory<>(Employee.class);
        System.out.println("create class factory success");

        try {
            ClassAsFactory<Integer> f1 = new ClassAsFactory<>(Integer.class);
        } catch (Exception e) {
            System.out.println("create integer class facotry failed");
        }
    }
}
